package main

import (
	"fmt"
	v1http "gitee.com/scottq/go-framework/src/v1/httpserver"
	v1log "gitee.com/scottq/go-framework/src/v1/log"
	"os"
	"path/filepath"
	"time"
)

func TestLog(logger v1log.ILog) {
	logger.Info("this is INFO")
	logger.Debug("this is DEBUG")
	logger.Warn("this is WARN")
	logger.Error("this is ERROR")
	//logger.Fatal("this is FATAL")
}

func main() {
	logPath := fmt.Sprintf("../runtime/logs/%s.log", filepath.Base(os.Args[0]))

	//log
	logger := v1log.NewZapLog("exampleApp", logPath, nil)

	TestLog(logger)
	TestLog(logger.Caller(-1))

	//invokeLog方式
	a := &v1log.InvokeLog{}
	a.AddLogger(logger)
	a.Info("hello")
	TestLog(a)

	//
	httpServer, err := v1http.NewHttpServer("exampleHttpServer", ":8080")
	if err != nil {
		logger.Error("run http server error:%s" + err.Error())
		panic(err)
	}
	httpServer.AddLogger(logger)

	go func() {
		time.Sleep(time.Second * 5)
		httpServer.Stop()
	}()

	httpServer.Run()
}
